package cn.leonis.leetcode;

/**
 * @Author Tobi
 * @Date 2021-12-10 下午5:21
 * 链表的中间节点
 * leetcode876
 */
public class MiddleLinkedListSolution {

    public static void main(String[] args) {

    }

    /**
     * 快慢指针法,一个走两步，一个走一步
     * @param head
     * @return
     */
    public ListNode middleNode(ListNode head) {
        ListNode slow = head, fast = head;
        while (fast != null && fast.next != null) {
            slow = slow.next;
            fast = fast.next.next;
        }
        return slow;
    }
}
